package org.example.completed.mapper;

import org.apache.ibatis.annotations.*;
import org.example.completed.domain.AnimalCategory;
import org.example.completed.domain.Animal;

import java.util.List;

@Mapper
public interface AnimalMapper {

    @Select("SELECT ac.label, ac.name AS category_name, a.name AS animal_name, a.id AS animal_id " +
            "FROM animal_category ac " +
            "LEFT JOIN animals a ON ac.id = a.category_id")
    @Results({
            @Result(property = "label", column = "label"),
            @Result(property = "name", column = "category_name"),
            @Result(property = "animals", column = "animal_name", many = @Many(select = "selectAnimals"))
    })
    List<AnimalCategory> getAllAdoptableAnimals();

    @Select("SELECT name, id FROM animals WHERE category_id = #{categoryId}")
    List<Animal> selectAnimals(int categoryId);
}
